<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	response.setHeader("X-Frame-Options","SAMEORIGIN");
	String ckType = request.getParameter("ckType");
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>CKEditor</title>
<script src="<%=basePath %>them/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="<%=basePath %>them/jquery-easyui-1.4.2/jquery.min.js"></script>
<script type="text/javascript">
	CKEDITOR.editorConfig = function( config ) {
		config.toolbar =
			[
			{ name: 'document', items: ['Source', '-', 'Preview'] },
			{ name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] },
			{ name: 'styles', items: ['Styles', 'Format', 'Font', 'FontSize'] },
			{ name: 'colors', items: ['TextColor', 'BGColor'] },
			{ name: 'tools', items: ['About'] },
			'/',
			{ name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'] },
			{ name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl'] },
			{ name: 'links', items: ['Link', 'Unlink', 'Anchor'] },
			{ name: 'insert', items: ['Image', 'Flash', 'Table', 'HorizontalRule', 'SpecialChar', 'PageBreak',] }
			
		];
		config.filebrowserImageUploadUrl = '<%=basePath%>upload/CKImgUpload';
		config.height=$(window).height()-160;
		
	};
	$(function(){
		fn_load();
	});
	CKEDITOR.on('instanceReady',function(e){
        if(html!=''){
        	CKEDITOR.instances.editor1.setData(html);
        }
	});
	var htmlContent = '';
	/* 刷新页面  也是查询功能   一进入页面就使用 */
	function fn_load(){
		var ckType = <%=ckType %>;
		$.ajax({
			type: "post",
			url: "<%=basePath %>ck/queryHtmlById",
			dataType: "json",
			data:{
				"ckType":ckType
			},
			success: function(msg) {
				var entity = msg.entity;
				var html = entity.html;
				CKEDITOR.instances.editor1.setData(html);
			}
		});
	}
	/* 保存修改功能 */
	function fn_save(){
		var ckType = <%=ckType %>;
		var html = CKEDITOR.instances.editor1.getData();
		if(html.replace(/\s/g, "")==""){
			alert("内容不允许为空值");
			return;
		}
		$.ajax({
			type: "post",
			url: "<%=basePath %>ck/updateCkHtml",
			dataType: "json",
			data:{
				"ckType":ckType,
				"html":html,
				"title":"CKEditorHtml"   /* 这个参数仅仅是为了区分是这个只有CKEditor页面传进后台的 */
			},
			success: function(msg) {
				var row = msg.row;
				if(row>=0){
					alert("修改成功！");
					
				}
			}
		});
	}
</script>
</head>
<body style="margin:0px">
<textarea class="ckeditor" id="editor1" name="editor1"></textarea>
<div style="width: 100%">
	<div style="margin-left: 40%">
		<input type="button" 
				style="background-color: #ed5736;width: 200px;height: 50px;border: 0px;font-size: 22px;color: white;border-radius: 30px;"
				value="保       存" onclick="fn_save()" />
		
	</div>
</div>

</body>
</html>